<?php
namespace app\index\controller;


class mController extends \app\base\controller\BaseController {

	public function index(){
		include CONFIG_PATH . 'siteconfig.php';
		$dev=self::get_device_type();
		$this->dev=$dev;
	    $this->display();
	}

	public function getindexdata(){
		
		//当前页面
		$page=$this->arg("p");

		$action=$this->arg("action");

		if(!$page || $page<=0){
			$page="1";
		}

		//一个页面显示条数
		$pageN="30";

		if($action=="search"){
		 $key=urldecode($this->arg("key"));
		 $where[]="`productName` LIKE  '%{$key}%'";


		}else{
		$where[]="1";
	    }
		
		$count=obj("api/Apidata")->Data_Count("goods",$where);

		//共分几页
		$indexpage=round($count/$pageN);
		$pagesize=($page-1)*$pageN;
		if($action=="search"){
		 $key=urldecode($this->arg("key"));
		 $sql[]="`productName` LIKE  '%{$key}%'";

		}else{
		$sql[]="1";
	    }
		$ret=obj("api/Apidata")->Data_Select("goods",$sql,"`date` DESC LIMIT {$pagesize} , {$pageN}");
		foreach ($ret as $key => $value) {
		$dec=mb_substr(strip_tags($value['productName']),0,73,'utf-8');

		$viewlink=url($route='go/to/url/id=<id>', $params=array('id'=>$value['id']));
		$date=obj("api/Api")->mdate($value['date']);

		$html='<div class="item">
	<div class="leftcontent">
		<a class="title" href="'.$viewlink.'" target="_blank" onmousedown="xlog(\''.$value['id'].'\',\'mindextitle\')">
			'.$value['productName'].'	</a>
		<div class="clear"></div>
		<div class="waitingload" style="display:none">正在读取详情，请稍候...</div>
		<div class="fullabstract" id="fullabstract" style="display:none"></div>
		<div class="clear"></div>
		<a class="thumbnail"  isconvert="1" href="'.$value['pcProductUrl'].'" target="_blank" onmousedown="xlog(\''.$value['id'].'\',\'mpic\')">
			<img src="'.$value['imgUrl'].'" alt="'.$value['productName'].'" style="width:70px;height:auto;margin-left:0px;margin-top:0px;margin-bottom:0px;margin-right:0px;">
		</a>
		<div class="infoandabstract">
			<div class="abstract">'.$dec.'...			</div>
			<div class="clear"></div>
								<div class="mallname">'.$value['mallName'].'</div>
								<div class="info"><span class="latesttime">'.$date.'</span>从&nbsp;'.$value['mallName'].'&nbsp;同步</div>
			<div class="clear"></div>
			<a class="buy"  isconvert="1"  href="'.$viewlink.'" target="_blank" onmousedown="xlog(\''.$value['id'].'\',\'mbuy\')"><span class="buyword">立即购买</span></a>
						<div class="more"><span class="idnum" style="display:none">'.$value['id'].'</span><span class="moreword">展开全文</span></div>
					</div>
	</div>
</div>
<div class="clear"></div>
';

     echo $html;

 }
	}


  //读取详情
  public function loadview(){
  	$id=$this->arg("id");
  	if(!is_numeric($id)){
  		exit('error');
  	}
   $where[] = "  `id` ={$id} ";
    $view = obj("api/Apidata")->Data_Select("goods", $where);
	$viewlink=url($route='go/to/url/id=<id>', $params=array('id'=>$value['id']));
	$date=obj("api/Api")->mdate($view['date']);
  	$html='
<div class="mallname">'.$view['mallName'].'</div>
<div class="info" style="float:left;margin-left:3%;"><span class="latesttime">'.$date.'</span></div>
<div class="clear"></div>
<span class="remoteabstract">'.$view['productName'].'</span>
<div class="clear"></div>

<div class="clear"></div>
<div class="buyframe">
	<a class="singlebuy"   isconvert="1"  href="'.$viewlink.'" target="_blank" onmousedown="xlog(\''.$view['id'].'\',\'mrankbuy\')">
		<span class="buyword">去'.$view['mallName'].'购买&nbsp;&gt;</span>
	</a>
</div>
';

echo $html;

  }


public function view(){
   $id=$this->arg("id");
  	if(!is_numeric($id)){
  		exit('error');
  	}
   $where[] = "  `id` ={$id} ";
   $view = obj("api/Apidata")->Data_Select("goods", $where);
   
  
   

	$this->view=$view;

    $this->display();

}


//风云榜
public function rank(){
	header("Content-type: text/html; charset=utf-8"); 
    //获取30分钟内热榜
   $token= new \ZhiCms\ext\weixin;
   $url="http://v2.api.haodanku.com/sales_list/apikey/wwwlegcom/sale_type/1";
   $rettime=obj("api/Api")->object_array(json_decode($token->http($url)));
    $time_a=date("H",time());
	$html.='<div class="rankhead">
	<div class="rankheadtitle">今日'.$time_a.'点档（'.date("Y-m-d",time()).' '.date("H:i", strtotime("-2 hour")).'-'.date("H:i",time()).'）</div>
   </div>';
  $rettime=$rettime['data'];
  foreach ($rettime as $key => $value) {
  $key=$key+1;
  $viewlink=url($route='go/tb/itemiid/id=<id>', $params=array('id'=>$value['itemid']));
  $html.='<div class="rankitem">
	<div class="rankleftcontent">
		<div class="clear"></div>
		<a class="rankthumbnail" href="'.$viewlink.'" target="_blank">
			<img src="'.$value['itempic'].'" style="width:70px;height:auto;margin-left:0px;margin-top:0px;margin-bottom:0px;margin-right:0px;">
		</a>
		<div class="rankinfoandabstract">
			<div class="rankinfo">No.'.$key.'</div>
			<div class="clear"></div>
			<a class="ranktitle" href="'.$viewlink.'" target="_blank">
				'.$value['itemtitle'].'			</a>
			<div class="clear"></div>
			<div class="rankmore rankmoreclick" style="float:left;"><a href="'.$viewlink.'" target="_blank"><span class="moreword" >立刻查看</span></a></div>
		</div>
		<!--div class="clear"></div>
		<div class="waitingload" style="display:none">正在读取详情，请稍候...</div>
		<div class="fullabstract" style="display:none;"></div-->
	</div>
</div>
<div class="clear"></div>
';

}
echo $html;

}

//九块九
public function cheaps(){
		include CONFIG_PATH . 'siteconfig.php';
        //当前页面
		$page=$this->arg("p");

		if(!$page || $page<=0){
			$page="1";
		}

		//一个页面显示条数
		$pageN="30";

		$where[]="1";
		
		$count=obj("api/Apidata")->Data_Count("youhuiquan",$where);

		//共分几页
		$indexpage=round($count/$pageN);
		$pagesize=($page-1)*$pageN;

		$sql[]="1";
		$ret=obj("api/Apidata")->Data_Select("youhuiquan",$sql,"`id` DESC LIMIT {$pagesize} , {$pageN}");
		foreach ($ret as $key => $value) {

		//$quanlink="http://uland.taobao.com/coupon/edetail?activityId={$value['Quan_id']}&pid={$Siteinfo['pid']}&itemId={$value['GoodsID']}&dx=1";
		$quanlink=url($route='go/tb/itemiid/id=<id>', $params=array("id"=>$value['goodsId']));
	$html='<div class="cheapitem">
	<div class="cheapleftcontent">
		<div class="clear"></div>
		<a class="cheapthumbnail" isconvert=1 href="'.$quanlink.'" target="_blank">
			<img src="'.$value['mainPic'].'" alt="'.$value['dtitle'].'" style="width:70px;height:70px;margin-left:0px;margin-top:0px;margin-bottom:0px;margin-right:0px;">
		</a>
		<div class="cheapinfoandabstract">
			<div class="clear"></div>
			<a class="cheaptitle" isconvert=1 href="'.$quanlink.'" target="_blank">
				'.$value['title'].'			</a>
			<div class="clear"></div>
			<div class="cheapinfo"><span style="font-size:10px">券后&nbsp;&yen;</span>'.$value['actualPrice'].'</div>
			<a class="buy" isconvert=1 href="'.$quanlink.'" target="_blank"><span class="buyword">购买&gt;</span></a>
						<a class="coupon" href="'.$quanlink.'" target="_blank"><span class="couponword">领'.$value['couponPrice'].'元券</span></a>
					</div>
	</div>
</div>
<div class="clear"></div>
';

echo $html;

}
}


public function search(){

	$this->display('app/index/view/m/index');
}

public function get_device_type()
{
 //全部变成小写字母
 $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
 $type = 'other';
 //分别进行判断
 if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))
{
 $type = 'ios';
 } 
  
 if(strpos($agent, 'android'))
{
 $type = 'android';
 }
 return $type;
}

}